<?php

namespace App\Http\Controllers\admin;

use DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class DebugController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex(Request $request)
    {
        /*搜索条件始*/
        //搜索条件
        $get['dev'] = $request -> input('dev','');
        /*搜索条件末*/
        //查询debug表
        $info = DB::table('debug')
            -> where('DevE','like','%'.$get['dev'].'%')
            -> select(
            'DevE',
            DB::raw("FROM_UNIXTIME(tmst,'%Y-%m-%d %H:%i:%s') as tmst"),
            'gwad',
            'freq',
            'datr',
            'rssi',
            'lsnr',
            'chan',
            'fcnt',
            'fprt',
            'datar'
        ) -> paginate(10);
        return view('admin.debug.index',['data'=>$info,'request'=>$request -> all(),'get'=>$get]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getCreate()
    {
        $jsonstr = '{"num":"SK005285","agent_id":1,"DevEUI":"0000000000000391","status":1,"loc":"","rname":"502\u623f\u95f4","bname":"\u91d1\u6d77\u5546\u52a1\u697c","aname":"\u90d1\u5dde\u5e02\u4e8c\u4e03\u533a","type":"\u70df\u611f","genre":"\u81ea\u68c0","degree":"\u6e29\u5ea6:-1\u2103","time":"1523395862","lsnr":4}';
        $arr = json_decode($jsonstr,true);
        // dd($arr);
        DB::table('alllog')->insert($arr);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
